package com.lanou3g.Hw0516;

import com.lanou3g.Hw0516.common.Constant;
import com.lanou3g.Hw0516.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "WelcomeServlet",urlPatterns = "/welcome")
public class WelcomeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession();
        User user= (User) session.getAttribute(Constant.Session.USER);
        if (user==null){
            //还没有登录
            response.sendRedirect(request.getContextPath()+"/user/login.jsp");
        }else {
            //代表登录过了
            request.getRequestDispatcher("/WEB-INF/welcome.jsp").forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request,response);

    }
}
